home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsfunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.2 KB  |  110 lines

  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsfunc.c,v 1.4 2000/09/19 19:00:28 lpd Exp $ */
  20. /* Generic Function support */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gsparam.h"
  24. #include "gxfunc.h"
  25.  
  26. /* GC descriptors */
  27. public_st_function();
  28.  
  29. /* Generic free_params implementation. */
  30. void
  31. fn_common_free_params(gs_function_params_t * params, gs_memory_t * mem)
  32. {
  33.     gs_free_const_object(mem, params->Range, "Range");
  34.     gs_free_const_object(mem, params->Domain, "Domain");
  35. }
  36.  
  37. /* Generic free implementation. */
  38. void
  39. fn_common_free(gs_function_t * pfn, bool free_params, gs_memory_t * mem)
  40. {
  41.     if (free_params)
  42.     gs_function_free_params(pfn, mem);
  43.     gs_free_object(mem, pfn, "fn_common_free");
  44. }
  45.  
  46. /* Check the values of m, n, Domain, and (if supplied) Range. */
  47. int
  48. fn_check_mnDR(const gs_function_params_t * params, int m, int n)
  49. {
  50.     int i;
  51.  
  52.     if (m <= 0 || n <= 0)
  53.     return_error(gs_error_rangecheck);
  54.     for (i = 0; i < m; ++i)
  55.     if (params->Domain[2 * i] > params->Domain[2 * i + 1])
  56.         return_error(gs_error_rangecheck);
  57.     if (params->Range != 0)
  58.     for (i = 0; i < n; ++i)
  59.         if (params->Range[2 * i] > params->Range[2 * i + 1])
  60.         return_error(gs_error_rangecheck);
  61.     return 0;
  62. }
  63.  
  64. /* Get the monotonicity of a function over its Domain. */
  65. int
  66. fn_domain_is_monotonic(const gs_function_t *pfn, gs_function_effort_t effort)
  67. {
  68. #define MAX_M 16        /* arbitrary */
  69.     float lower[MAX_M], upper[MAX_M];
  70.     int i;
  71.  
  72.     if (pfn->params.m > MAX_M)
  73.     return gs_error_undefined;
  74.     for (i = 0; i < pfn->params.m; ++i) {
  75.     lower[i] = pfn->params.Domain[2 * i];
  76.     upper[i] = pfn->params.Domain[2 * i + 1];
  77.     }
  78.     return gs_function_is_monotonic(pfn, lower, upper, effort);
  79. }
  80.  
  81. /* Return default function information. */
  82. void
  83. gs_function_get_info_default(const gs_function_t *pfn, gs_function_info_t *pfi)
  84. {
  85.     pfi->DataSource = 0;
  86.     pfi->Functions = 0;
  87. }
  88.  
  89. /* Write generic parameters (FunctionType, Domain, Range) on a parameter list. */
  90. int
  91. fn_common_get_params(const gs_function_t *pfn, gs_param_list *plist)
  92. {
  93.     int ecode = param_write_int(plist, "FunctionType", &FunctionType(pfn));
  94.     int code;
  95.  
  96.     if (pfn->params.Domain) {
  97.     code = param_write_float_values(plist, "Domain", pfn->params.Domain,
  98.                     2 * pfn->params.m, false);
  99.     if (code < 0)
  100.         ecode = code;
  101.     }
  102.     if (pfn->params.Range) {
  103.     code = param_write_float_values(plist, "Range", pfn->params.Range,
  104.                     2 * pfn->params.n, false);
  105.     if (code < 0)
  106.         ecode = code;
  107.     }
  108.     return ecode;
  109. }
  110.